﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace hse_2013_photo_viewer
{
    public partial class PictureViewingUI : UserControl
    {
        
        PhotoBrowsing provider = new PhotoBrowsing();
        private int counter = 0;
        public string path = "C:\\";
        public Action RenewUI;
        
        public PictureViewingUI()
        {
            InitializeComponent();
            
        }

        public void SetPicture()
        {
           
            if (counter <= provider.LoadPictures(path).Count - 1 && counter >= 0)
            {
                mainPictureBox.Load(@provider.LoadPictures(path)[counter]);
                labelFileName.Text = Path.GetFileNameWithoutExtension(provider.LoadPictures(path)[counter]);
            }
        }

        

        void SetNextPicture()
        {
            if (counter <= provider.LoadPictures(path).Count - 2 && counter >= 0)
            {
                counter++;
                SetPicture();
            }
            
            
            
        }

        void SetPrevPicture()
        {
            if (counter >= 1 && counter <= provider.LoadPictures(path).Count - 1)
            {
                counter--;
                mainPictureBox.Load(@provider.LoadPictures(path)[counter]);
            }
        }

        private void ButtonNext_Click(object sender, EventArgs e)
        {
            SetNextPicture();
        }

        private void PictureViewingUI_Load(object sender, EventArgs e)
        {
            SetPicture();
            RenewUI += new Action(SetPicture);
        }

        private void ButtonPrev_Click(object sender, EventArgs e)
        {
            SetPrevPicture();
        }

        
    }
}
